package com.splant.android.smart.ModelLevel;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.splant.android.R;
import com.splant.android.smart.UILevel.Community.Garden_Detector_Activity;

/**
 * Created by Administrator on 2017/8/23.
 */

public class DetectorMapObject {

    private View detectorView;
    private float leftScale;
    private float topScale;
    private ImageView img_detector;
    private TextView tv_detectorName;
    private Activity activity;
    private DetectorListBean.Detector detector;
    public DetectorMapObject(final Activity activity, final DetectorListBean.Detector detector) {

        this.activity=activity;
        this.detector=detector;

        detectorView = activity.getLayoutInflater().inflate(R.layout.garden_map_detector, null);
        img_detector = (ImageView) detectorView.findViewById(R.id.img_detector);
        tv_detectorName = (TextView) detectorView.findViewById(R.id.tv_detectorName);
        tv_detectorName.setText(detector.getDetectorName());

        if (detector.getDetectorState() == 1) {

            if (detector.getAbnState() == 0)
                img_detector.setImageResource(R.mipmap.garden_ic_map_detector_normal);
            else
                img_detector.setImageResource(R.mipmap.garden_ic_map_detector_abnormal);

        } else {
            img_detector.setImageResource(R.mipmap.garden_ic_map_detector_offline);
        }

        img_detector.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (tv_detectorName.getVisibility() == View.VISIBLE)
                    tv_detectorName.setVisibility(View.INVISIBLE);
                else
                    tv_detectorName.setVisibility(View.VISIBLE);

            }
        });
//        img_detector.setOnLongClickListener(new View.OnLongClickListener() {
//            @Override
//            public boolean onLongClick(View v) {
//                if (tv_detectorName.getVisibility() == View.VISIBLE)
//                    tv_detectorName.setVisibility(View.INVISIBLE);
//                else
//                    tv_detectorName.setVisibility(View.VISIBLE);
//
//                return true;
//            }
//        });

        tv_detectorName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(activity, Garden_Detector_Activity.class);
                intent.putExtra("detector", detector);
                activity.startActivity(intent);

            }
        });

        img_detector.setClickable(false);
    }

    public void showHideDeviceName(boolean b)
    {
        if (b)
        {
            img_detector.setClickable(true);
            tv_detectorName.setClickable(true);
        }
        else
        {
            img_detector.setClickable(false);
            tv_detectorName.setClickable(false);
        }
    }

    public void setLeftScale(float leftScale) {
        this.leftScale = leftScale;
    }

    public float getLeftScale() {
        return this.leftScale;
    }

    public void setTopScale(float topScale) {
        this.topScale = topScale;
    }

    public float getTopScale() {
        return this.topScale;
    }

    public void setDetectorView(View detectorView) {
        this.detectorView = detectorView;
    }

    public View getDetectorView() {
        return this.detectorView;
    }
}
